package deepbitview

/**
 * a simple tablib to ease the generation of code in the menu
 */
class StatisticsTagLib {

    static namespace = "deepbit"

    /**
     * renders a checkbox
     */
    def renderCheckbox = { attr, body ->

        String url = createLink(controller:attr.controller,action:attr.action)

        String id = attr.id
        String title = attr.title
        String days = (attr.days != null) ? attr.days : 1

        out << """

<span class="label">
                                                <input type="hidden" name="_${id}" /><input type="checkbox" name="${id}" id="${id}"  />
                                            </span>
                                            <span class="value">
                                                ${title}
                                            </span>

                                            <script type="text/javascript">

                                                \$(document).ready(function() {


                                                    \$('#${id}').click(function() {

                                                        if (\$('#${id}').is(':checked')) {

                                                            jQuery.ajax({
                                                                url: "${url}",
                                                                type: "POST",
                                                                data: ({day:\$('#days_selector').val()}),
                                                                success: function(result) {
                                                                    \$('#content').append('<div id="${id}_1"></div>');
                                                                    \$('#${id}_1').append(result);

                                                        \$(".post-bgtop").corner().removeShadow();
                                                        \$(".post-bgtop").corner().dropShadow();
                                                                }
                                                            });

                                                        }
                                                        else {
                                                            \$('#${id}_1').remove();

                                                        \$(".post-bgtop").corner().removeShadow();
                                                        \$(".post-bgtop").corner().dropShadow();
                                                        }




                                                    });

                                                });





</script>




        """
    }

}
